//
//  MYGHealthManagementStatisticsCell.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit

class MYGHealthManagementStatisticsCell: MYGHealthManagementBaseCell {
    // MARK: - Property
    override var model: MYGHealthManagementRowModel? {
        didSet {
            guard let model = (model as? MYGHealthManagementStatisticsModel) else { return }
            titleLabel.text = model.title
            titleLabel.textColor = model.themeColor
            iconImageView.image = UIImage(named: model.icon)
            bgImageView.image = UIImage(named: model.bgImageName)
            keyLabel1.text = model.key1
            keyLabel2.text = model.key2
            valueLabel1.text = model.value1
            valueLabel2.text = model.value2
        }
    }
    

    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .white
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.addSubviews([
            bgImageView
        ])
        
        bgImageView.addSubviews([
            iconImageView,
            titleLabel,
            keyLabel1,
            valueLabel1,
            keyLabel2,
            valueLabel2,
        ])
        
        bgImageView.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.left.right.equalToSuperview().inset(22.5)
            make.height.equalTo(104)
            make.bottom.equalToSuperview()
        }
        
        iconImageView.snp.makeConstraints { make in
            make.top.equalTo(16.5)
            make.left.equalTo(13.5)
            make.size.equalTo(CGSize(width: 22, height: 22))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(4.5)
            make.centerY.equalTo(iconImageView)
            make.height.equalTo(21)
        }
        
        valueLabel1.snp.makeConstraints { make in
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.left.equalTo(13.5)
            make.height.equalTo(22.5)
            make.width.equalTo(95)
        }
        
        keyLabel1.snp.makeConstraints { make in
            make.top.equalTo(valueLabel1.snp.bottom).offset(5.5)
            make.left.equalTo(13.5)
            make.height.equalTo(16.5)
            make.width.equalTo(95)
        }
        
        valueLabel2.snp.makeConstraints { make in
            make.centerY.equalTo(valueLabel1)
            make.left.equalTo(valueLabel1.snp.right).offset(40)
            make.height.equalTo(22.5)
            make.width.equalTo(95)
        }
        
        keyLabel2.snp.makeConstraints { make in
            make.centerY.equalTo(keyLabel1)
            make.left.equalTo(keyLabel1.snp.right).offset(40)
            make.height.equalTo(16.5)
            make.width.equalTo(95)
        }

    }
    
    // MARK: - lazy load
    private lazy var bgImageView: UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.isUserInteractionEnabled = true
        return imageV
    }()
    
    private lazy var iconImageView: UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        return imageV
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(15)
        return label
    }()
    
    private lazy var valueLabel1: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .black
        return label
    }()
    
    private lazy var keyLabel1: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(139, 139, 139)
        return label
    }()
    
    private lazy var valueLabel2: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .black
        return label
    }()
    
    private lazy var keyLabel2: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(139, 139, 139)
        return label
    }()
}
